<template>
	<view class="content">
		<u-modal v-model="show" :content="content" show-cancel-button='true' @confirm='confirm()'></u-modal>
		<u-tabs :list="list" :is-scroll="false" :current="current" @change="change" :bar-width="130"
			active-color="#0062B6"></u-tabs>
		<view class="contentList" v-if="dataList.length!=0" style="background-color: #d0d0d0;">
			<view class="list" @click="link(item.orderId,item.orderState)" v-for="(item,index) in dataList" :key='index'>
				<view class="listTop">
					订单编号：{{item.orderCode}}
					<!-- <view class="listDelBottom "  v-if="item.orderState==2">
						<view class="listBottom">
							<view class="jxz  jxz1">已支付</view>
						</view>
					</view> -->
					<view class="listDelBottom "  v-if="item.orderState==3||item.orderState==4">
						<view class="listBottom">
							<view class="jxz  jxz2">退款中</view>
						</view>
					</view>
					<view class="listDelBottom "  v-if="item.orderState==5||item.orderState==6">
						<view class="listBottom">
							<view class="jxz  jxz2">已退款</view>
						</view>
					</view>
				</view>
				<view class="listCenter">
					<image src="../../static/chack.png" mode="" v-if="item.type=='all'"></image>
					<image src="../../static/chadc.png" mode="" v-if="item.type=='dc'"></image>
					<view class="listCenterT">
						<view class="titles" v-if="item.type=='all'">查综合车况</view>
						<view class="titles" v-if="item.type=='dc'">查电池</view>
						<view class="titles" v-if="item.type=='sg'">查维保</view>
						<view class="titlesBottom">
							<view class="jg">￥{{item.amountZf}}</view>
						</view>
					</view>
				</view>
				

				
				<view class="titlesBottom" style="height: 92rpx;line-height: 92rpx;" >
					
					<view class="listBottom" >
						<view class="time">时间：{{item.createTime}}</view>
						<view class="ckbg" @click.stop="fk1(item)" v-if="item.orderState==1">付款</view>
						<view class="ckbg ckbg1"  v-if="item.orderState==2">查看报告</view>
					</view>
				</view>	
				
			</view>
		</view>
		<view v-else>
			<null></null>
		</view>
		
		<u-toast ref="uToast" />
	</view>
</template>

<script>
	import API from "@/api/my.js"
	import API1 from "@/api/report.js"
	export default {
		data() {
			return {
				https: getApp().globalData.picturePath,
				list: [{
					name: '待支付',
				}, {
					name: '已完成',
				}, {
					name: '部分退款',
				}, {
					name: '全部退款',
				}],
				current: 0,
				orderState:'',
				dataList:[],
				show: false,
				content: '确定取消订单吗',
				detectionOrderId:"",
				token:'',
				orderId:''
			}
		},
		onLoad(option) {
			let that = this;
			if(option.type){
				this.current = option.type
			}
			
			this.detectionOrder()
			uni.getStorage({
			    key: 'token',
			    success: function (res) {
			        that.token = res.data
			    }
			});
		},
		methods: {
			ckbg(item){
				console.log(item)
				if(item.type=='all'){
					uni.navigateTo({
							url:"/pagesB/carReport/carReportDetail?orderId="+item.orderId
						})
				}else if(item.type=='dc'){
					uni.navigateTo({
							url:"/pagesB/carReport/carReportDetail1?orderId="+item.orderId
						})
				}else{
					uni.navigateTo({
							url:"/pagesB/carReport/carReportDetail2?orderId="+item.orderId
						})
				}
			},
			confirm(){
				// let that = this;
				// let data  = {
				// 	detectionOrderId:this.detectionOrderId,
				// }
				// API.orderStatusCancel(data).then(res=>{
				// 	// this.dataList = res.data
				// 	console.log(res)
				// 	that.detectionOrder();
				// })
			},
			fk1(item){
				console.log(item)
				API1.bocheIncidentOrdercreateOrderBatch({
					imagesAndVins:item.imagesAndVinsJson,
					type: item.type
				}).then(res => {
					let that = this;
					if (res.code == 200) {
						console.log(res)
						that.orderId = res.dataTwo
				
						uni.requestPayment({
						         provider: 'wxpay',
						         timeStamp: res.data.timeStamp,//时间戳
						         nonceStr: res.data.nonceStr,//随机字符串
						         package: res.data.package,//统一下单接口返回的 prepay_id 参数值
						         signType: res.data.signType,
						          paySign: res.data.paySign,//签名内容
						          success: function (res) {
									 console.log(res)
						             that.$refs.uToast.show({
						             	title: '付款成功',
						             	type:'success',
						             	callback:function(){
											
						             		that.detectionOrder1();
						             	}
						             })
						          },
						          fail: function (err) {
						             console.log('fail:' + JSON.stringify(err));
						          }
						      });
					} else {
						this.$u.toast('识别失败，请重新输入Vin！');
					}
				
				})
			},
			detectionOrder1(){
				let that = this;
				let data = {
					token:this.token,
					orderId:this.orderId
				}
				uni.request({
					url: 'https://www.ibuycar.com.cn/wx/zhck/getBocheIncidentReport',
					data: data,
				    method: 'GET',
					success: ((res) => {
						console.log(res)
						 // uni.hideLoading()
					    if (res.data.code == 200) {
							// resolve(res.data)
							this.$refs.uToast.show({
								title: '报告生成中',
								type:'success',
								callback:function(){
									that.detectionOrder()
								}
							})
					    }else if(res.data.code==999){
							uni.showToast({title: "订单不正确",icon:"none"});
						}else{
							uni.showToast({title: res.url + "订单异常支付金额将24小时内原路退回",icon:"none"});
						}
					}),
					fail: ((obj) => {
						
						uni.showToast({title: obj.url + "订单异常支付金额将24小时内原路退回",icon:"none"});
					})
			})
			},
			// qxdd(detectionOrderId){
			// 	this.detectionOrderId = detectionOrderId;
			// 	this.show = true;
			// },
			qxdd(detectionOrderId){
				// this.detectionOrderId = detectionOrderId;
				// this.show = true;
				uni.navigateTo({
					url:'/pagesB/delRefund/delRefund?detectionOrderId='+detectionOrderId
				})
			},
			change(index) {
				this.current = index;
				this.detectionOrder();
			},
			link(orderId,type){
				if(type==1){
					return false
				}
				uni.navigateTo({
					url:'/pagesB/pgddList/pgddList?orderId='+orderId
				})
			},
			detectionOrder(){
				
				let that = this;
				let token = uni.getStorage({
					token: token
				})
				console.log(that.current)
				if(that.current==0){
					that.orderState=1
				}else if(that.current==1){
					that.orderState='2'
				}else if(that.current==2){
					that.orderState='3,5'
				}else if(that.current==3){
					that.orderState='4,6'
				}
				let data  = {
					token:token,
					page:1,
					limit:99999,
					orderState:this.orderState
				}
				API.wxzhckbocheIncidentOrderlist(data).then(res=>{
					console.log(res)
					this.dataList = res.data
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.time{
		font-family: PingFangSC-Regular;
		font-size: 28rpx !important;
		color: #999999;
	}
	// .jxz2{
	// 	color: #0062B6 !important;
	// }
	.vins{
		width: 400rpx;
		white-space:nowrap;
		overflow:hidden;
		text-overflow:ellipsis;
	}
	.jg{
		font-family: PingFangSC-Medium;
		    font-size: 34rpx;
		    color: #FF552E;
	}
	.fk{
		background: #0062B6;
		width: 136rpx;
		height: 68rpx;
		font-size: 28rpx;
		color: #FFFFFF;
		line-height: 68rpx;
		text-align: center;
		border-radius: 4rpx;
		margin-top: 12rpx;
		margin-left: 40rpx;
	}
	// .jxz1{
	// 	color: #EF9F43 !important;
	// }
	.list{
		margin-top: 14rpx;
	}
	.list {
		padding: 0 32rpx 15rpx;
		background: #fff;
		
	}

	.listTop {
		width: 100%;
		height: 100rpx;
		line-height: 100rpx;
		font-size: 28rpx;
		color: #4F4F4F;
		border-bottom: 1px solid #EFEFEF;
		display: flex;
		justify-content: space-between;
	}

	.listCenter {
		display: flex;
		padding: 34rpx 0 0;
		// border-bottom: 1px solid #EFEFEF;
		image{
			width: 95rpx;
			height: 81rpx;
		}
	}
	.listCenterT{
		margin-left: 42rpx;
		line-height: 80rpx;
		width: 600rpx;
		display: flex;
		justify-content: space-between;
	}
	.titles{
		font-size: 34rpx;
		font-family: PingFangSC-Medium;
		color: #2C2C2C;
		
	}
	.titlesBottom{
		display: flex;
		justify-content: space-between;
		// margin-top: 12rpx;
		font-size: 28rpx;
		color: #4F4F4F;
	}
	.money{
		font-family: PingFangSC-Medium;
		font-size: 34rpx;
		color: #FF552E;
	}
	.fk{
	border: 1px solid #666666;
		width: 136rpx;
		height: 68rpx;
		font-size: 28rpx;
		color: #666666;
		line-height: 68rpx;
		text-align: center;
		border-radius: 4rpx;
		margin-top: 12rpx;
		margin-left: 40rpx;
	}
	.ckbg1 {
		    background: #DD4835 !important;
		    border: none !important;
		    color: #fff !important;
	}
	
	.ckbg{
		border: 1px solid #666666;
		width: 136rpx;
		height: 68rpx;
		font-size: 28rpx;
		color: #666666;
		line-height: 68rpx;
		text-align: center;
		border-radius: 4rpx;
		margin-top: 12rpx;
		margin-left: 40rpx;
	}
	.listBottom{
		    height: 100rpx;
		    line-height: 100rpx;
		    display: flex;
		    float: right;
		    font-size: 28rpx;
		    justify-content: space-between;
		    width: 100%;
	}
	.listBottom1{
		display: flex;
		width: 100%;
		justify-content: space-between;
	}
	.listDelBottom{
		height: 100rpx;
		display: flex;
		justify-content: space-between;
	}
	.jxz{
		font-size: 28rpx;
		color: #0062B6;
		text-align: center;
	}
</style>